import sj_show_modal from '@/components/G_show_modal/index.js';
let ssm;
const showModal = (op = {}) => {
	console.info("ddd");
	return new Promise((resolve, reject) => {
		ssm = new sj_show_modal({
			...op,
			$event: (e) => {
				if (e.res) {
					resolve(e);
				} else {
					reject(e);
				}
			}
		})
		ssm.show();

	})

}

export default {
	state: {
		token: uni.getStorageSync('token'),//"f1c9db99f2cf59ba2fa849681acdfc14",//uni.getStorageSync('token'),
		userInfo:"",
		selectcart:{},
		
		isinit:0,//0 否 1是
	},
	mutations: {
		setinit(state,val){
			state.isinit = val;
		},
		//修改数据
		async updatebaseItem(state, item) {
			console.info("修改数据",item);
			let {
				key,
				val
			} = item;
			state[key] = val;
		},
		setselectcart(state,val){
			state.selectcart = val;
		},
	},
	actions: {
		// 获取基本配置
		async getConfigInfo({
			commit,
			state
		}, param) {
			
			commit('updateConfigItem', {
				key: 'configInfo',
				val: {}
			})
		},
		asyncInrement(context) {
		  return new Promise(resolve => {
		    resolve();
		  });
		},
		tislogin(){
			// #ifdef APP-PLUS
			try{
				ssm.hide();
			}catch(e){
				console.info(e,"报错了!!!");
			}
			// #endif
			showModal({
				title:'提示',
				concent:'你还未登录，是否前往登录',
				confirmVal:'去登录',
				cancelVal:'继续体验',
			}).then(res=>{
				let pages = getCurrentPages()
				let len = pages.length;
				let curParam = pages[len - 1]; //获取当前页面参数
				console.info('curParam',curParam.route);
				if(curParam.route.indexOf("login")==-1){
					uni.navigateTo({
						url: "/pages/login/login?isfanhui=1",
					})
				}else{
					console.info("已在登录页面了~");
				}
			})
		},
		
		
	}
}
